package aole.object;

/*
 * File: Plane.java
 * Author: Bhupendra Aole
 * Date: 30-sep-06
 * 
 */
import aole.math.Vec3;

/**
 * An Infinite Plane object.
 * @author bhupendra
 *
 */
public class Plane extends Renderable {
	// sphere intersections count
	public static int count = 0;

	// normal to the intersection point
	public Vec3 normal = new Vec3();

	// D component of the plane.
	// distance from origin
	public float D;

	@Override
	public float calcIntersection (Vec3 p, Vec3 dir) {
		count++;
		float vd = Vec3.dot(dir, normal);
		if (vd < 0) {
			float t = -(Vec3.dot(p, normal) + D) / vd;
			if (t > 0)
				return t;
		}
		return -1f;
	}

	// Normal of a plane is constant throughout the plane
	@Override
	public Vec3 getNormal (Vec3 ip) {
		return normal;
	}

	public void readnormal (String s) {
		normal.read(s);
		normal.normalize();
	}

	public void readd (String s) {
		D = Float.parseFloat(s);
	}

	@Override
	public String toString () {
		return "Plane:<" + normal.x + "," + normal.y + "," + normal.z + ">,"
				+ D;
	}
}
